package controller;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.RoomModel;
import service.RoomService;
import service.impl.RoomServiceImpl;

/**
 * Servlet implementation class RoomServlet
 */
@WebServlet("/RoomServlet/*")
public class RoomServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private RoomService roomservice=new RoomServiceImpl();
   
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String path=request.getPathInfo().substring(1);
		if("listAll".equals(path)){
			listAll(request,response);
		}
		if("listType".equals(path)){
			listType(request,response);
		}
	}
	
	private void listAll(HttpServletRequest request, HttpServletResponse response) {
		try {
			List<RoomModel> roomlist = roomservice.listAll();
			request.setAttribute("roomlist",roomlist);
			request.getRequestDispatcher("../room.jsp").forward(request,response);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	private void listType(HttpServletRequest request, HttpServletResponse response) {
		try {
			List<RoomModel> roomlist = roomservice.listType();
			request.setAttribute("roomlist",roomlist);
			request.getRequestDispatcher("../index.jsp").forward(request,response);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
